package com.gxa.modules.sys.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gxa.common.utils.Result;
import com.gxa.modules.sys.dto.PurchaseDto;
import com.gxa.modules.sys.service.PurchaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Api(tags = "用户购买记录接口")
@RestController
@Slf4j
public class PurchaseController {

    @Autowired
    private PurchaseService purchaseService;

//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "body",name = "page",value ="当前是第几页",dataType ="int"),
//            @ApiImplicitParam(paramType = "body",name = "limit",value ="每页显示多少条",dataType ="int"),
//            @ApiImplicitParam(paramType = "body",name = "userId",value ="查询条件",dataType ="int"),
//            @ApiImplicitParam(paramType = "body",name = "userTel",value ="查询条件",dataType ="String"),
//            @ApiImplicitParam(paramType = "body",name = "areaId",value ="查询条件",dataType ="int"),
//            @ApiImplicitParam(paramType = "body",name = "channel",value ="查询条件",dataType ="int"),
//    })

    @ApiOperation(value="用户购买记录查询接口")
    @PostMapping("/coupon/purchase/list")
    public Result queryCouponPurchase(@RequestBody PurchaseDto purchaseDto){
        try {
            Page<Map<String,Object>> pageHelperList = PageHelper.startPage(purchaseDto.getPage(),purchaseDto.getLimit());
            List<PurchaseDto> purchaseList = this.purchaseService.queryCouponPurchase(purchaseDto);
            Map map = new HashMap();
            map.put("purchase",purchaseList);
            map.put("count",pageHelperList.getTotal());
            return  new Result().ok(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result().error("查询失败");
        }
    }
}
